package cn.okcmd.log_logback.subtest.defconf;

/**
 * create by caoqg on 2021/7/15
 * 功能说明:
 */


import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.html.HTMLLayout;
import ch.qos.logback.classic.spi.Configurator;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.status.Status;

/**
 * create by caoqg on 2021/7/13
 * 功能说明:
 */
public class MyConfigurator extends ContextAwareBase implements Configurator {
    @Override
    public void configure(LoggerContext loggerContext) {
        addInfo("use my config");
        ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
        ca.setContext(loggerContext);
        ca.setName("console");
        LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<ILoggingEvent>();
        encoder.setContext(loggerContext);

        HTMLLayout layout = new HTMLLayout();
        layout.setContext(loggerContext);
        layout.start();
        encoder.setLayout(layout);
        encoder.start();

        ca.setEncoder(encoder);
        ca.start();

        Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
        logger.addAppender(ca);
    }


}
